package com.basic.rewrite;

import java.util.HashMap;

public class ObjRewriete {

	public static void main(String[] args) {
		Person person = new Person(1, "zhangsan");
		HashMap<Person, String> persons = new HashMap<>();
		persons.put(person, "test");
		Person personKey = new Person(1, "zhangsan");
		System.out.println(persons.get(personKey));
	}
	
	static class Person{
		
		private int id;
		
		private String name;

		public Person(int id, String name) {
			super();
			this.id = id;
			this.name = name;
		}

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
		
		@Override
		public int hashCode() {
			return this.id;
		}
		
		@Override
		public boolean equals(Object obj) {
			Person personSurce = (Person)obj;
			return personSurce.getId() == this.id;
		}
	}
}
